package cn.dujc.superkid.adapter;


import android.support.annotation.Nullable;
import android.webkit.WebView;
import android.widget.RadioButton;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import java.util.List;
import cn.dujc.core.adapter.BaseAdapter;
import cn.dujc.core.adapter.BaseViewHolder;
import cn.dujc.superkid.R;
import cn.dujc.superkid.bean.SubjectEntity;

public class RecyclerViewAdapter extends BaseAdapter<SubjectEntity> {
    private WebView textView;
    public RecyclerViewAdapter(@Nullable List<SubjectEntity> data) {
        super(data);
        mLayoutResId = R.layout.item_good_que;
    }
    @Override
    protected void convert(BaseViewHolder helper, SubjectEntity item) {
        // 点击事件
        helper.addOnClickListener(R.id.good_continu).addOnClickListener(R.id.good_resolvtion);
        // title 赋值
        textView = helper.getView(R.id.good_que_title);
        ImageLoader imageLoader = ImageLoader.getInstance();//ImageLoader需要实例化
        imageLoader.init(ImageLoaderConfiguration.createDefault(mContext));
        textView.loadData(item.getQuestion_title(), "text/html; charset=UTF-8", null);
        // answers 赋值
        int size = item.getExercises_answer().size();
        switch (size) {
            default:
            case 4:
                ((RadioButton)helper.getView(R.id.answerD)).setText(item.getExercises_answer().get(3));
            case 3:
                ((RadioButton)helper.getView(R.id.answerC)).setText(item.getExercises_answer().get(2));
            case 2:
                ((RadioButton)helper.getView(R.id.answerB)).setText(item.getExercises_answer().get(1));
                ((RadioButton)helper.getView(R.id.answerA)).setText(item.getExercises_answer().get(0));
                break;
            case 1:
                helper.setGone(R.id.exercise_answer, false);
        }
    }
//    // 删除数据
    public void removeData(int position) {
        getData().remove(position);
        //删除动画
        notifyItemRemoved(position);
        notifyDataSetChanged();
    }
}